package com.wnhz.work.jy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wnhz.work.jy.BaseActivity;
import com.wnhz.work.jy.R;
import com.wnhz.work.jy.bean.HomeFragment1.RecommendBean;

import org.xutils.x;

import java.util.List;

/**
 * Created by d on 2016/10/17.
 */
public class SelectGoodAdapter extends BaseAdapter {
    private Context context;

    private List<RecommendBean> list;

    private View.OnClickListener listener;

    public SelectGoodAdapter(Context context, List<RecommendBean> list, View.OnClickListener listener) {
        this.context = context;
        this.list = list;
        this.listener = listener;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        MyHolder holder;
        if (view == null){
            holder = new MyHolder();
            view = LayoutInflater.from(context).inflate(R.layout.iten_select_good,null);

            holder.tv_price = (TextView) view.findViewById(R.id.tv_price);
            holder.good_name = (TextView) view.findViewById(R.id.good_name);
            holder.number_tv = (TextView) view.findViewById(R.id.number_tv);
            holder.reduce_img = (ImageView) view.findViewById(R.id.reduce_img);
            holder.add_img = (ImageView) view.findViewById(R.id.add_img);
            holder.img = (ImageView) view.findViewById(R.id.img);
            holder.stock_num = (TextView) view.findViewById(R.id.stock_num);

            view.setTag(holder);
        }
        holder = (MyHolder) view.getTag();
        holder.add_img.setTag(i);
        holder.reduce_img.setTag(i);
        holder.add_img.setOnClickListener(listener);
        holder.reduce_img.setOnClickListener(listener);
        if (list.get(i).getmYNum() == 0){
            holder.reduce_img.setImageResource(R.mipmap.ic_decase_nor);
        }else {
            holder.reduce_img.setImageResource(R.mipmap.ic_decase);
        }
        x.image().bind(holder.img,list.get(i).getGoodImg());
        holder.number_tv.setText(list.get(i).getmYNum()+"");
        holder.good_name.setText(list.get(i).getGoodName());
        holder.stock_num.setText("库存数量: "+list.get(i).getStoreNum());
        holder.tv_price.setText("¥"+list.get(i).getGoodPrice());

        return view;
    }

    private class MyHolder{

        ImageView add_img,reduce_img,img;
        TextView good_name,tv_price,number_tv,stock_num;
    }
}
